Skip to content

Conversation

mariopaja
Copy link
Contributor

@mariopaja mariopaja commented Sep 10, 2025

Workaround for drivers that use HAL_OVERRIDE hack and skips Zephyr API. #93480 (comment)

This change fixes DMA stream ID for H7xx series for the following peripherals:

  1. dcmi
  2. sai1_a
  3. sai1_b

DMA stream ID should be in range 1..N

samples/drivers/i2s/output

Before:

I2S device not ready
[00:00:00.000,000] <dbg> i2s_stm32_sai: stm32_sai_enable_clock: Clock Control Device: <OK>
[00:00:00.000,000] <dbg> i2s_stm32_sai: stm32_sai_enable_clock: I2S clock Enable: <OK>
[00:00:00.000,000] <dbg> i2s_stm32_sai: stm32_sai_enable_clock: I2S domain clock configuration: <OK>
[00:00:00.000,000] <err> dma_stm32: cannot configure the dma stream -1.
[00:00:00.000,000] <err> i2s_stm32_sai: Failed to configure DMA channel 0
[00:00:00.000,000] <err> i2s_stm32_sai: i2s_stm32_sai_dma_init(): <FAILED>
*** Booting Zephyr OS build v4.2.0-3327-g599d0053b7de ***

After:

[00:00:00.000,000] <dbg> i2s_stm32_sai: stm32_sai_enable_clock: Clock Control Device: <OK>
[00:00:00.000,000] <dbg> i2s_stm32_sai: stm32_sai_enable_clock: I2S clock Enable: <OK>
[00:00:00.000,000] <dbg> i2s_stm32_sai: stm32_sai_eAll I2S blocks written
nable_clock: I2S domain clock configuration: <OK>
[00:00:00.000,000] <inf> i2s_stm32_sai: sai1@40015824 inited
*** Booting Zephyr OS build v4.2.0-3327-g599d0053b7de ***
[00:00:00.000,000] <dbg> i2s_stm32_sai: i2s_stm32_sai_configure: SAI_STEREOMODE
[00:00:00.000,000] <dbg> i2s_stm32_sai: i2s_stm32_sai_trigger: I2S_TRIGGER_START
[00:00:00.021,000] <dbg> i2s_stm32_sai: i2s_stm32_sai_trigger: I2S_TRIGGER_DRAIN
[00:00:00.029,000] <dbg> i2s_stm32_sai: HAL_SAI_TxCpltCallback: Exit TX callback, no more data in the queue

This change fixes DMA stream ID for H7xx series.
DMA stream ID should be in range 1..N

Signed-off-by: Mario Paja <[email protected]>
Copy link

@avolmat-st
Copy link

Thanks @mariopaja for this fix. I confirm that it does fix the issue. This is due to the update done within the PR #94869 which ensure to perform the DMA_OFFSET shift in all DMA function entry-points, leading to getting a -1 channel id for dcmi for example on the H7.
While this does fix the issue, I am wondering why we need to keep such indexing different depending on platforms.
@erwango, Maybe I missed on part but wouldn't it be easier from a user point of view to always have channel id starting from 0 for all platforms, and not having to set them starting from 1 on some and from 0 for some others ?

@erwango
Copy link
Member

erwango commented Sep 15, 2025

@erwango, Maybe I missed on part but wouldn't it be easier from a user point of view to always have channel id starting from 0 for all platforms, and not having to set them starting from 1 on some and from 0 for some others ?

Problem is that on some series (say F0), channel index starts from 1 and channels are bound to a dedicated peripheral (Ie channel 1 bound to ADC for instance). So we need to respect this, otherwise it'll make configuration quite hard.

Coming back on the current issue, I need to have a deeper look.
I agree we should be able to use index starting from 0 on H7, as allowed by the IP. Though, no the other side, when dmamux is present, we're not supposed to reference dma1/2 directly but rather we should always go through dmamux, ie:

-			dmas = <&dma1 0 75 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC |
+			dmas = <&dmamux1 0 75 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC |

But then @mariopaja raises #93480 (comment) on which I don't have answer for now. I'll come back to you on this.

@FRASTM
Copy link
Contributor

FRASTM commented Sep 29, 2025

On the stm32H7 which has a DMAMUX, use the dmamux for the corresponding peripheral request : (channel is the one from 0..15)
for dcmi request is 75 :
dmas = <&dmamux1 0 75 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC ...

for SAI 1 A request is 87 :
dmas = <&dmamux1 1 87 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC ...

for SAI 1 B request is 88 :
dmas = <&dmamux1 2 88 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC ...

And also enable DMAMUX1,DMA1,DMA2

&dma1 {
	status = "okay";
}
&dma2 {
	status = "okay";
};
&dmamux1 {
	status = "okay";
};

@mariopaja
Copy link
Contributor Author

@FRASTM you are correct about the request but channel of DMAMUX seems to be hardwired #93480 (comment) .

And here starts my issue because it gives a limitation. For example SAI1 A & B nodes cannot be used simultaneously

@FRASTM
Copy link
Contributor

FRASTM commented Sep 29, 2025

@FRASTM you are correct about the request but channel of DMAMUX seems to be hardwired #93480 (comment) .

And here starts my issue because it gives a limitation. For example SAI1 A & B nodes cannot be used simultaneously

Did you try with SAI 1 A and SAI 2 B
SAI 2B request is 90 :
dmas = <&dmamux1 2 90 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC ...

@mariopaja
Copy link
Contributor Author

@FRASTM you are correct about the request but channel of DMAMUX seems to be hardwired #93480 (comment) .

And here starts my issue because it gives a limitation. For example SAI1 A & B nodes cannot be used simultaneously

Did you try with SAI 1 A and SAI 2 B

SAI 2B request is 90 :

dmas = <&dmamux1 2 90 (STM32_DMA_PERIPH_TO_MEMORY | STM32_DMA_PERIPH_NO_INC ...

I will not be able to test it before 06/10.

I think we have also drifted a bit from my issue. I tried to explain it once again at sai g4 PR

Copy link
Member

@erwango erwango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Talking directly to DMA instances is the only possible solution (today) for drivers implemented using HAL.

Copy link
Contributor

@mathieuchopstm mathieuchopstm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per binding, this really shouldn't be needed. But issue seems to be caused by:

#elif defined(CONFIG_DMA_STM32_V1) && defined(CONFIG_DMAMUX_STM32)
/* typically on the stm32H7 series, DMA V1 with mux */
#define STM32_DMA_STREAM_OFFSET 1
#else

acceptable workaround until DMA stuff is cleaned up

@jhedberg jhedberg merged commit 5ab7ef6 into zephyrproject-rtos:main Sep 30, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants